package com.generalaj.console.builder;

import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;
import org.beetl.core.resource.FileResourceLoader;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by wangxin on 2017/2/24.
 */
public class TemplatesTools {

    private String root;
    private File initWorkspaceTemplate;

    public void init(String templatesRoot) throws IOException {
        this.root=templatesRoot;
        initWorkspaceTemplate=new File(templatesRoot+ File.separator+"init_workspace"+File.separator+"init_workspace.job");
    }


    public File getInitWorkspaceTemplate() {
        return initWorkspaceTemplate;
    }

    public Template getTemplate(String path) throws IOException {
        FileResourceLoader resourceLoader = new FileResourceLoader(root,"utf-8");
        Configuration cfg = Configuration.defaultConfiguration();
        GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
        Template t = gt.getTemplate(path);
        return t;
    }

}
